﻿using BootstrapBlazor.Components;
using System;

namespace BlazorAdmin.Interface
{
    public class AppQueryOption
    {
        public AppQueryOption()
        {

        }

        public AppQueryOption(QueryPageOptions options, string currentUser)
        {
            this.Option = options;
            this.CurrentUser = currentUser;
        }

        public QueryPageOptions Option { get; set; }

        public VsmQuerySql Sql { get; set; }

        /// <summary>
        /// 当前用户
        /// </summary>
        public string CurrentUser { get; set; }
    }

    public class AppQueryOption<T>: AppQueryOption
    {
        public AppQueryOption()
        {

        }

        public AppQueryOption(QueryPageOptions options)
        {
            this.Option = options;
        }

        public AppQueryOption(string currentUser)
        {
            this.CurrentUser = currentUser;
        }

        public AppQueryOption(QueryPageOptions options, string currentUser)
        {
            this.Option = options;
            this.CurrentUser = currentUser;
        }

        public T Param { get; set; }
    }

    public class VsmQuerySql
    {
        public VsmQuerySql()
        {

        }

        public VsmQuerySql(string sql)
        {
            SQL = sql;
        }

        public VsmQuerySql(string sql, params object[] args)
        {
            SQL = sql;
            Params = args;
        }

        public bool IsSingleTable { get; set; }

        public string CurrentUser { get; set; }

        public string SQL { get; set; }

        public object[] Params { get; set; }

        public string OrderBy { get; set; } = string.Empty;

        #region 内部方法

        public bool IsAdmin()
        {
            if (!string.IsNullOrEmpty(CurrentUser))
                return CurrentUser.Equals("Admin", StringComparison.CurrentCultureIgnoreCase);
            else
                return false;
        }

        #endregion
    }
}
